package org.soarsky.wealthchengdu.google.map;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;

public class PointItemOverlays extends ItemizedOverlay<OverlayItemPoint> {
	ArrayList<OverlayItemPoint> overlayItems = new ArrayList<OverlayItemPoint>();
	private int index = -1;
	private Drawable defaultMarker = null;
	private boolean drawableSizeChange = false;
	public PointItemOverlays(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		this.defaultMarker = defaultMarker;
		overlayItems.clear();
		populate();
	}

	public PointItemOverlays() {
		super(null);
	}

	@Override
	public void setLastFocusedIndex(int lastFocusedIndex) {
		// TODO Auto-generated method stub
		super.setLastFocusedIndex(lastFocusedIndex);
	}

	@Override
	public void setDrawFocusedItem(boolean drawFocusedItem) {
		// TODO Auto-generated method stub
		super.setDrawFocusedItem(drawFocusedItem);
	}

	public PointItemOverlays(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		this.defaultMarker = defaultMarker;
		overlayItems.clear();
		populate();
	}

	public Drawable boundCenterBottoms(Drawable marker) {
		return boundCenterBottom(marker);
	}

	public void addOverlay(OverlayItemPoint overlayItem) {
		overlayItems.add(overlayItem);
		populate();
	}

	public void addOverlay(int location, OverlayItemPoint overlayItem) {
		overlayItems.add(location, overlayItem);
		populate();
	}

	public void removeOverlay(int i) {
		overlayItems.remove(i);
		populate();
	}

	public void doPopulate() {
		populate();

	}

	@Override
	protected OverlayItemPoint createItem(int i) {
		// TODO Auto-generated method stub
		return overlayItems.get(i);
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		if (overlayItems != null)
			return overlayItems.size();
		else
			return 0;
	}

	@Override
	protected boolean onTap(int index) {
		// callBack.Result(index);
		this.index = index;
		return true;
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		// TODO Auto-generated method stub
		super.draw(canvas, mapView, shadow);
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public int getIndex() {
		return index;
	}

	public void clear() {
		overlayItems.clear();
		setLastFocusedIndex(-1);
		doPopulate();
	}

	public void destroy() {
		if (overlayItems != null) {
			overlayItems.clear();
			overlayItems = null;
		}
	}

	public Drawable getDefaultMarker() {
		// TODO Auto-generated method stub
		return defaultMarker;
	}

	public boolean isDrawableSizeChange() {
		return drawableSizeChange;
	}

	public void setDrawableSizeChange(boolean drawableSizeChange) {
		this.drawableSizeChange = drawableSizeChange;
	}

}
